module  Caches
  def self.append_features(base)
    base.after_create do |object|
      Caches::apaga_caches
      puts "-------------- Create - Apangado Cache --------------"
    end
    base.after_update do |object|
      Caches::apaga_caches
      puts "-------------- Update - Apangado Cache --------------"      
    end
    base.after_destroy do |object|
      Caches::apaga_caches
      puts "-------------- Destroy - Apangado Cache --------------"      
    end
  end  
  
  def self.apaga_caches
    $CACHES_STATUS.each do |c|
      Rails.cache.delete(c) if Rails.cache.exist?(c)
    end
  end
end
